package com.thouiot.modbus.exception;

import com.thouiot.common.exception.IErrorCode;

/**
 * @description modbus模块错误码枚举
 * @author wangkai
 * @date 2025/04/11 08:49
 */
public enum ModbusErrorCodeEnum implements IErrorCode {
    ERROR(-1, "失败"),
    SUCCESS(0, "成功"),

    // 串口通信相关异常 10001 - 10099
    SERIAL_PORT_OPEN_ERROR(10001, "串口打开失败"),
    SERIAL_OPEN_INPUT_ERROR(10002, "串口输入开启失败"),
    SERIAL_OPEN_OUTPUT_ERROR(10003, "串口输出开启失败"),

    // 参数相关异常  20001 - 20099
    PARAM_EMPTY_ERROR(20001, "参数不能为空"),
    MASTER_NAME_EMPTY_ERROR(20002, "主机名称不能为空"),
    SLAVE_ID_EMPTY_ERROR(20003, "从机地址不能为空"),
    OFFSET_EMPTY_ERROR(20004, "寄存器地址不能为空"),
    MASTER_TYPE_EMPTY_ERROR(20005, "主机类型不能为空"),
    MASTER_TYPE_NOT_SUPPORT(20006, "主机类型不支持"),
    REGISTER_TYPE_ERROR(20007, "寄存器类型错误"),
    WRITE_MODBUS_ERROR(20008, "写入Modbus失败"),
    DATA_TYPE_EMPTY_ERROR(20009, "数据类型不能为空"),
    READ_VALUE_TYPE_ERROR(20010, "读取值类型错误"),
    READ_VALUE_TYPE_NOT_MATCH(20011, "寄存器类型与数据类型不匹配"),
    WRITE_VALUE_TYPE_NOT_MATCH(20012, "写入参数值类型不匹配"),

    REGISTER_TYPE_MATCH_VALUE_ERROR(20013, "寄存器类型与值不匹配"),

    WRITE_PARAM_EMPTY_ERROR(20014, "写入参数不能为空"),
    SLAVE_NAME_EMPTY_ERROR(20015, "从机名称不能为空"),
    MODBUS_SLAVE_NOT_FOUND(20016, "从机不存在"),
    MODBUS_MASTER_NOT_FOUND(20017, "主机不存在"),

    // modbus 操作相关异常  30001 - 30099
    MODBUS_SLAVE_SET_ERROR(30001, "设置Modbus Slave 失败"),
    ;

    private final int code;

    private final String msg;

    ModbusErrorCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }
}
